package weeny.pre.renderer;

import java.lang.reflect.Field;

import prefuse.data.expression.Predicate;
import prefuse.render.DefaultRendererFactory;
import prefuse.render.Renderer;
import prefuse.render.RendererFactory;
import prefuse.util.PredicateChain;
import prefuse.visual.VisualItem;

public class MoreRendererFactory implements RendererFactory{
	DefaultRendererFactory m_drf = null;
	public MoreRendererFactory() {
		m_drf = new DefaultRendererFactory();
	}
	public MoreRendererFactory(Renderer defaultRenderer){
		m_drf = new DefaultRendererFactory(defaultRenderer);
	}
	public MoreRendererFactory(Renderer itemRen, Renderer edgeRen){
		m_drf = new DefaultRendererFactory(itemRen, edgeRen);
	}
	public void add(String predicate, Renderer r){
		m_drf.add(predicate, r);
	}
	public void add(Predicate p, Renderer r){
		m_drf.add(p, r);
	}
	public void remove(Predicate p){
		try{
			Field chainField = m_drf.getClass().getDeclaredField("m_chain");
			chainField.setAccessible(true);
			PredicateChain chain = (PredicateChain) chainField.get(m_drf);
			System.out.println(chain.remove(p));
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	public Renderer getRenderer(VisualItem item) {
		return m_drf.getRenderer(item);
	}
}